package com.feriaderemates.dao.listing;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.feriaderemates.domain.listing.FixedPriceListing;
import com.feriaderemates.domain.listing.ItemCondition;
import com.feriaderemates.domain.listing.ListingStatus;
import com.feriaderemates.domain.listing.ListingType;

import com.feriaderemates.domain.listing.SaleType;

public class FixedPriceListingRowMapper implements RowMapper {

	@Override
	public Object mapRow(ResultSet rs, int i) throws SQLException {
		FixedPriceListing fixedlist = FixedPriceListing.createFixedPriceListing(rs.getString("username"));
		fixedlist.setListingId(rs.getLong("listing_id"));
		fixedlist.setDescription(rs.getString("description"));
		fixedlist.setNumber_of_views(rs.getInt("number_of_views"));
		fixedlist.setWarranty(rs.getString("warranty"));
		fixedlist.setListingStatus(ListingStatus.valueOf(rs.getString("listing_status")));
		fixedlist.setSaleType(SaleType.valueOf(rs.getString("sale_type")));
                fixedlist.setListingType(ListingType.valueOf(rs.getString("listing_type")));
		fixedlist.setPrice(rs.getBigDecimal("price"));
		fixedlist.setQuantity(rs.getInt("quantity"));
		fixedlist.setAcceptingReturns(rs.getBoolean("accept_returns"));
		fixedlist.setReturnRules(rs.getString("return_rules"));
		fixedlist.setDaysToProcessShipment(rs.getInt("days_to_process_shipment"));
		fixedlist.setItemCondition(ItemCondition.valueOf(rs.getString("item_condition")));
		fixedlist.setAcceptingOffers(rs.getBoolean("accept_offers"));
		fixedlist.setRequiresImmediatePayment(rs.getBoolean("requires_immediate_payment"));
		fixedlist.setTitle(rs.getString("title"));
                fixedlist.setSubTitle(rs.getString("sub_title"));
		return fixedlist;
	}

}
